home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.unix.programmer,comp.lang.c
- Subject: Re: Runtime ANSI C checking tool?
- Date: Thu, 07 Mar 96 17:28:17 GMT
- Organization: none
- Message-ID: <826219697snz@genesis.demon.co.uk>
- References: <DnI89B.EnH@pgh.nauticom.net> <p5ag239ede.fsf@lemming.wellfleet.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <p5ag239ede.fsf@lemming.wellfleet.com>
- psmith@wellfleet.com "Paul D. Smith" writes:
-
- >%% Regarding Runtime ANSI C checking tool?;
- >%% tybergm@pgh.nauticom.net (Mark E. Tyberg) writes:
- >
- > met> Does anyone know of a program (for UNIX) that can do _runtime_
- > met> checking for ANSI C violations/undefined behavior?
- >
- >Well, a well-written ANSI C compiler should handle all language
- >violations, and a well-written ANSI C system library should catch all
- >runtime violations (passing NULL to strcpy() or something, for
- >example).
-
- Not possible in general (at least for the compiler or the standard library)
- e.g.
-
- int foo(int *p, int *q)
- {
- return ++*p + ++*q;
- }
-
- This results in undefined behaviour if the same value is passed for p and
- q.
-
- >Some vendors try to be cute and allow you to pass invalid args to
- >standard functions without complaint by catching them and ignoring them
- >(SunOS in particular does this a lot--not that SunOS's libc is ANSI by
- >any stretch of the imagination :), but I say they should catch them and
- >call abort() immediately! They're not doing you any favors by making it
- >that much more difficult to find your bug. Dump core up front! Make it
- >easy to find the problem!
-
- You can catch null pointers by making sure that address 0 is mapped out
- of your address space - that isn't a job for the standard library. I agree
- that it is better not to have any error checking than error checking that
- simply causes the error condition to be passed over.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-